import { createStore, applyMiddleware } from 'redux'
import thunk from 'redux-thunk'
const initState = {
    shopList: [],
    carList: []
}
const loadState = () => {
    return JSON.parse(localStorage.getItem('redux'))
}
function reducer(state = initState, action) {
    let { type, data } = action
    switch (type) {
        case 'addShop':
            state.shopList = data
            return { ...state };
        case 'addCarList':
            let list = [...state.carList]
            list.push(data)
            state.carList = list
            console.log(state.carList)
            return { ...state };

        case 'ChangsetC':   
            let car = JSON.parse(JSON.stringify(data))
            state.carList = car
            return { ...state };
        default: return { ...state };
    }
}
export default createStore(reducer, loadState(), applyMiddleware(thunk))